package com.bawei.exam57.base

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider

abstract class BaseFragment<VDB : ViewDataBinding,VM: ViewModel>:Fragment() {
    lateinit var binding:VDB
    lateinit var viewModel:VM
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        binding=DataBindingUtil.inflate(inflater,getLayoutId(),container,false)
        viewModel=ViewModelProvider(this)[getViewModelClass()]
        initView()
        initData()
        return binding.root
    }

    abstract fun initView()

    abstract fun initData()

    abstract fun getViewModelClass(): Class<VM>

    abstract fun getLayoutId(): Int
}